//
//  SemPageCell.m
//  i5db
//
//  Created by iMuse on 15-5-16.
//  Copyright (c) 2015年 mySelf. All rights reserved.
//

#import "SemPageCell.h"
#import "AppCenter.h"

@implementation SemPageCell
{
    NSInteger        numberCount;
}

-(void)initView
{
    self.backgroundColor = [UIColor clearColor];
    
    
    if (self.dataSource && [self.dataSource respondsToSelector:@selector(semPageView:)])
    {
        numberCount = [self.dataSource semPageView:self];
    
    }
    

    
    NSArray* array = [NSArray arrayWithObjects:@"我的举办聚会",@"我参加的聚会", nil];
    for (NSInteger i =0; i<numberCount; i++)
    {
        UIView * view = [[UIView alloc] init];
        UILabel * label = [[UILabel alloc] init];
        label.text = [array objectAtIndex:i];
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:14];
        
        view.tag = i;
        view.backgroundColor = [UIColor clearColor];
        view.frame = CGRectMake(i*(SCREEN_WIDTH/2), 0, SCREEN_WIDTH/2, 30);
        
        label.frame = CGRectMake(0, 0, view.frame.size.width, view.frame.size.height);
        
        [view addSubview:label];
        
        UITapGestureRecognizer * gester = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(didSelectView:)];
        [view addGestureRecognizer:gester];
        
        [self addSubview:view];
    }
    
   
}

-(void)didSelectView:(UITapGestureRecognizer*) sender
{

    for (UIView * view in self.subviews)
    {
        view.layer.borderWidth = 0;
    }
    
    NSInteger tag = sender.view.tag;
    UIView * currentView = sender.view;
    currentView.layer.borderWidth = 1;
    currentView.layer.borderColor = [AppCenter color:@"76,187,248,1"].CGColor;
    
    if ([self.dataSource respondsToSelector:@selector(semPageView:didSelectAtIndex:)])
    {
        [self.dataSource performSelector:@selector(semPageView:didSelectAtIndex:) withObject:[NSString stringWithFormat:@"%d",tag]];
    }
    
    if ([self.delegate respondsToSelector:@selector(semPageView:cellForPageAtIndex:)])
    {
        [self.delegate performSelector:@selector(semPageView:cellForPageAtIndex:) withObject:self withObject:[NSString stringWithFormat:@"%d",tag]];
    }
}








@end
